import Toast from 'react-native-root-toast';
import utils from './Utils';
//非队列式toast,每次toast时上次的toast会先隐藏.
//TODO 全局性队列式设置
let toast;

const toa=(msg,obj)=>{ 
  console.log(`toast:[${utils.time}] ${msg},${obj}`);
  
  obj=obj||{};
  toast && Toast.hide(toast);
  toast = Toast.show(msg, {
    duration: obj.duration||Toast.durations.LONG,
    position: obj.positions||Toast.positions.CENTER,
    shadow: obj.shadow||true,
    animation: obj.animation||true,
    hideOnPress: obj.hideOnPress||true,
    delay: obj.delay||0
  });
  return toast;
}

const tst=(msg,obj)=>{
  if(!msg && msg!==false)return toa(msg,obj)
  if(utils.isType(msg,'object')){
    msg=JSON.stringify(msg);
  }
  msg=msg.toString();
  return toa(msg,obj);
}


tst.short=(msg)=>tst(msg,{duration:Toast.durations.SHORT});

export default tst;
